<template>
  <div class="login-container">
    <div class="login-wrapper">
      <div class="login-card">
        <div class="login-header">
          <h1>欢迎注册</h1>
          <p>请输入您的用户名和密码以继续</p>
        </div>

        <!-- 登录表单 -->
        <el-form :model="form" :rules="rules" ref="formRef">
          <!-- 用户名 -->
          <el-form-item prop="username" class="form-item">
            <el-input
              v-model="form.username"
              placeholder="用户名"
              prefix-icon="el-icon-user"
              class="input-field"
            />
          </el-form-item>

          <!-- 密码 -->
          <el-form-item prop="password" class="form-item">
            <el-input
              v-model="form.password"
              type="password"
              placeholder="密码"
              prefix-icon="el-icon-lock"
              show-password
              class="input-field"
            />
          </el-form-item>

          <!-- 注册按钮 -->
          <el-form-item class="button-group">
            <el-button type="primary" @click="submitForm" class="login-btn">
              注册
            </el-button>
          </el-form-item>
        </el-form>

        <div class="login-footer">
          <p>已经有账号？<a @click="goToLogin">点击登录</a></p>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';

const router = useRouter();

// 表单数据
const form = reactive({
  username: '',
  password: '',
});

// 表单验证规则
const rules = reactive({
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
});

// 表单引用
const formRef = ref();

// 提交表单
const submitForm = () => {
  formRef.value.validate((valid: boolean) => {
    if (valid) {
      // 模拟登录逻辑
      console.log('登录表单数据：', form);
      ElMessage.success('登录成功！');
      router.push('/dashboard'); // 跳转到首页
    } else {
      ElMessage.warning('请填写完整信息');
    }
  });
};

// 跳转到登录页面
  const goToLogin = () => {
    router.push('/login');
  };

</script>

<style scoped>
/* 页面容器 */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url('https://source.unsplash.com/1600x900/?nature,forest'); /* 背景图 */
  background-size: cover;
  background-position: center;
}

/* 登录卡片容器 */
.login-wrapper {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 400px;
  text-align: center;
}

/* 登录卡片 */
.login-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 登录标题 */
.login-header h1 {
  font-size: 28px;
  font-weight: bold;
  color: #333;
  margin-bottom: 10px;
}

.login-header p {
  font-size: 14px;
  color: #666;
}

/* 表单项 */
.form-item {
  margin-bottom: 20px;
}

.input-field {
  width: 100%;
  border-radius: 8px;
}

/* 按钮组 */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-btn,
.register-btn {
  width: 100%;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
}

.login-btn {
  background-color: #6a11cb;
  border: none;
  color: white;
}

.login-btn:hover {
  background-color: #2575fc;
}

/* 底部链接 */
.login-footer {
  font-size: 14px;
  color: #666;
}

.login-footer a {
  color: #6a11cb;
  text-decoration: none;
}

.login-footer a:hover {
  text-decoration: underline;
}
</style>